package com.study.servlet.servletcontext.redirect;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
* @Name: ServletRedirectSource
* @Description: 利用Http的Response响应头信息，实现请求重定向源
* 重定向特点：
* 	1、地址发生变化；
* 	2、实际是对服务器做了两次请求；
* 	3、放在request域中的数据在重定向页面中不能取；
* @Author: 李超	lc_jack@foxmail.com
* @CreateDate: 2017-3-1 上午9:12:30 
* @Version: V1.0
 */
public class ServletRedirectSource extends HttpServlet {

	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
//		response.setStatus(302) ;
//		response.setHeader("Location", "/java-servlet/servlet/ServletRedirectTarget") ;
		response.sendRedirect("/java-servlet/servlet/ServletRedirectTarget") ;
	}

	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		this.doGet(request, response);
	}

}
